package com.mxx.springaction;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * 这个需要单独实现而不能在bean上实现，因为这个处理的bean类需要在我们注入的所有bean之前先注入
 */
public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessAfterInitialization(Object arg0, String arg1)
            throws BeansException {
        if (arg0 instanceof Knight) {
            System.out
                    .println("8.BeanPostProcessor接口方法postProcessAfterInitialization对属性进行更改！");
        }
        return arg0;
    }

    @Override
    public Object postProcessBeforeInitialization(Object arg0, String arg1)
            throws BeansException {
        if (arg0 instanceof Knight) {
            System.out
                    .println("6.BeanPostProcessor接口方法postProcessBeforeInitialization对属性进行更改！");
        }

        return arg0;
    }
}